package cn.itcast.spring;

import static org.junit.Assert.*;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.itcast.spring.demo1.CustomerProxy;
import cn.itcast.spring.demo1.CustomerService;
import cn.itcast.spring.demo1.CustomerServiceImpl;
import cn.itcast.spring.demo2.OrderServiceImpl;
import cn.itcast.spring.demo2.OrderServiceProxy;
import cn.itcast.spring.demo3.AccountService;

public class AopTest {

	
	@Test
	public void getJdkProxy() throws Exception {
		CustomerService service = new CustomerServiceImpl();
		CustomerProxy customerProxy = new CustomerProxy(service);
		CustomerService createCustomerServiceProxy = customerProxy.createCustomerServiceProxy();
		createCustomerServiceProxy.eat();
	}
	
	
	@Test
	public void getCglibProxy() throws Exception {
		OrderServiceImpl impl = new OrderServiceImpl();
		OrderServiceProxy proxy = new OrderServiceProxy(impl);
		OrderServiceImpl createOrderServiceImpl = proxy.createOrderServiceImpl();
		createOrderServiceImpl.add();
		createOrderServiceImpl.delete();
	}
	
	
	
	
	/**
	 * spring通过xml的方式来配置实现我们的切面编程
	 */
	@Test
	public void getAccountProxy() throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext2.xml");
		AccountService bean = (AccountService) context.getBean("accountService");
		//前置通知
		//bean.add();
		//后置通知
//		bean.delete();
		//环绕通知
//		bean.update();
		//异常通知
//		bean.find();
//		最终通知
		bean.batch();
	}
	
	
	
	
	
	
	
	

}
